package cn.king.springframework.context.support;

import cn.king.springframework.beans.BeanException;
import cn.king.springframework.beans.factory.ConfigurableListableBeanFactory;
import cn.king.springframework.beans.factory.support.DefaultListableBeanFactory;
import cn.king.springframework.context.support.AbstractApplicationContext;

public abstract class AbstractRefreshableApplicationContext extends AbstractApplicationContext {
    private DefaultListableBeanFactory beanFactory;
    @Override
    protected void refreshBeanFactory() throws BeanException {
        beanFactory = createBeanFactory();
        loadBeanDefinitions(beanFactory);
        this.beanFactory = beanFactory;

    }

    private DefaultListableBeanFactory createBeanFactory(){
        return new DefaultListableBeanFactory();
    }

    protected abstract void loadBeanDefinitions(DefaultListableBeanFactory beanFactory);

    @Override
    protected ConfigurableListableBeanFactory getBeanFactory() {
        return beanFactory;
    }
}
